﻿using DevExpress.ExpressApp.DC;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Xpo;
using EasyXaf.EntityDesigner.BusinessObjects.Entities;

namespace EasyXaf.EntityDesigner.BusinessObjects.Entities.EntityViews;

/// <summary>
/// 实体视图
/// </summary>
[XafDisplayName("实体视图")]
[XafDefaultProperty(nameof(DisplayName))]
public partial class EntityView : BaseObject
{
	private EntityViewType _viewType;
	private string _viewId;
	private string _viewCaption;
	private bool _defaultView;
	private string _viewLayout;
	private Entity _entity;

	/// <summary>
	/// 显示名称
	/// </summary>
	[XafDisplayName("显示名称")]
	public string DisplayName
	{
		get => GetDisplayName();
	}

	/// <summary>
	/// 视图类型
	/// </summary>
	[XafDisplayName("视图类型")]
	public EntityViewType ViewType
	{
		get => _viewType;
		set => SetPropertyValue(nameof(ViewType), ref _viewType, value);
	}

	/// <summary>
	/// 视图Id
	/// </summary>
	[XafDisplayName("视图Id")]
	public string ViewId
	{
		get => _viewId;
		set => SetPropertyValue(nameof(ViewId), ref _viewId, value);
	}

	/// <summary>
	/// 视图标题
	/// </summary>
	[XafDisplayName("视图标题")]
	public string ViewCaption
	{
		get => _viewCaption;
		set => SetPropertyValue(nameof(ViewCaption), ref _viewCaption, value);
	}

	/// <summary>
	/// 默认视图
	/// </summary>
	[XafDisplayName("默认视图")]
	public bool DefaultView
	{
		get => _defaultView;
		set => SetPropertyValue(nameof(DefaultView), ref _defaultView, value);
	}

	/// <summary>
	/// 视图布局
	/// </summary>
	[XafDisplayName("视图布局")]
	[EditorAlias("CodeEditor")]
	[Size(SizeAttribute.Unlimited)]
	public string ViewLayout
	{
		get => _viewLayout;
		set => SetPropertyValue(nameof(ViewLayout), ref _viewLayout, value);
	}

	/// <summary>
	/// 实体
	/// </summary>
	[XafDisplayName("实体")]
	[Association("Entity-Views")]
	public Entity Entity
	{
		get => _entity;
		set => SetPropertyValue(nameof(Entity), ref _entity, value);
	}

	public EntityView(Session session)
		: base(session)
	{
	}

	private partial string GetDisplayName();
}
